/**
 * 
 */
package com.lemote.action.account;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lemote.action.BaseAction;
import com.lemote.core.PropertyFilter;
import com.lemote.entity.Group;
import com.lemote.entity.Role;
import com.lemote.exception.AppException;
import com.lemote.service.account.GroupService;
import com.lemote.service.account.RoleService;
import com.lemote.utils.CheckUtils;

/**
 * @author wuhui
 *
 * 下午02:34:15
 */
@Component("groupAction")
public class GroupAction extends BaseAction<Group, GroupService> {

	private Group entity;
	
	private List<Long> checkedRoleIds;//页面中钩选的角色id列表
	
	private RoleService roleService;
	
	@Override
	public String delete() throws AppException {
		if (ids!=null&&ids.length()>0) {
			entityService.delete(CheckUtils.stringParse(ids));
		}
		return SUCCESS;
	}

	
	@Override
	public String input() throws AppException {
		prepareModel();
		return SUCCESS;
	}

	@Override
	public String list() throws AppException {
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(request);
		page = entityService.search(page, filters);
		return SUCCESS;
	}

	
	@Override
	public void prepareModel() throws AppException {
		if (id != null) {
			entity = entityService.get(id);
		} else {
			entity = new Group();
		}
	}

	
	@Override
	public String save() throws AppException {
		if (entity!=null) {
			if (entity.getId()==null) {
				entityService.add(entity);
			}else {
				entityService.update(entity);
			}
			return GLOBALSUCCESS;
		} 
		return ERROR;
	}

	@Autowired
	@Override
	public void setEntityService(GroupService entityService) {
		this.entityService = entityService;
	}

	
	public Group getModel() {
		
		return entity;
	}

	/**
	 * input页面显示所有角色列表.
	 */
	public List<Role> getAllRoleList() {
		
		return roleService.getAll();
	}
	
	public Group getEntity() {
		return entity;
	}


	public void setEntity(Group entity) {
		this.entity = entity;
	}


	public List<Long> getCheckedRoleIds() {
		return checkedRoleIds;
	}


	public void setCheckedRoleIds(List<Long> checkedRoleIds) {
		this.checkedRoleIds = checkedRoleIds;
	}

	@Autowired
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	
}
